<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\CoUserDistribution;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class CoUserDistributionController extends AdminController
{
    protected $title = '配送员审核';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CoUserDistribution(), function (Grid $grid) {
            $grid->model()
                ->where("is_shen",0)
                ->where('is_type',1)
                ->paginate(10);
            $grid->id->sortable();
            $grid->column('truename','配送员名称');
            $grid->column('tel','电话');
            $grid->column('gender','性别')->display(function ($val) {
                if ($val ==1) {
                    return "男";
                } else {
                    return "女";
                }
            });
            $grid->idcard;
            $grid->student_number;
            $grid->regist_date->sortable();
            $grid->column('is_shen','审核状态')->display(function ($val) {
                if ($val ==1) {
                    return "审核通过";
                } elseif($val ==2) {
                    return "审核未通过";
                }else{
                    return "待审核";
                }
            });
            $grid->disableCreateButton();
            $grid->disableFilter();

            $grid->actions(function ($actions) {

                // 去掉删除
                $actions->disableDelete();

                // 去掉编辑
//                $actions->disableEdit();

                // 去掉查看
                $actions->disableView();
            });
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CoUserDistribution(), function (Show $show) {
            $show->id;
            $show->truename;
            $show->tel;
            $show->gender;
            $show->idcard;
            $show->student_number;
            $show->idcard_img_r;
            $show->idcard_img_l;
            $show->studentcard_img_r;
            $show->studentcard_img_r;
            $show->regist_date;
            $show->is_shen;
            $show->remarks;
            $show->created_at;
            $show->updated_at;
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CoUserDistribution(), function (Form $form) {
            $form->hidden('id');
            $form->hidden('status')->default(1);
            $form->text('truename','配送员名字')->readonly();
//            $form->display('avatar','头像')->with(function ($value) {
//                return "<img src='$value' style='width: 100px;height: 100px;' />";
//            });
            $form->display('tel','电话');
            $form->display('gender','性别')->with(function ($value) {
                if($value == 1){
                    return '男';
                }else{
                    return '女';
                }
            });
            $form->text('idcard')->readonly();
            $form->text('student_number')->readonly();
            $form->display('idcard_img_r')->with(function ($value) {
                return "<img src='$value' style='width: 100px;height: 100px;' />";
            });
            $form->display('idcard_img_l')->with(function ($value) {
                return "<img src='$value' style='width: 100px;height: 100px;' />";
            });
            $form->display('studentcard_img_r','学生证封面或一卡通正面')->with(function ($value) {
                return "<img src='$value' style='width: 100px;height: 100px;' />";
            });
            $form->display('studentcard_img_r','学生证内页或一卡通反面')->with(function ($value) {
                return "<img src='$value' style='width: 100px;height: 100px;' />";
            });
            $form->radio('is_shen','审核状态')->options([1=>'审核通过',2=>'不通过'])->required()->default(1);
            $form->text('remarks')->required();
            $form->disableDeleteButton();
            $form->disableViewButton();
            $form->footer(function ($footer) {
                // 去掉`重置`按钮
                $footer->disableReset();

                // 去掉`查看`checkbox
                $footer->disableViewCheck();

                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();

                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
            });
        });
    }
}
